package controllers.shared;

import javax.swing.JOptionPane;

/* Loops until the user either enters a String or presses cancel */
/* Returns a String if a user enters something */
/* Returns null if Cancel was pressed */
public class GetInputLoop {
	
	private static Object message;
	private static String title;
	private static int type;
	
	private static Object errorMessage;
	private static String errorTitle;
	
	public GetInputLoop() {}
	
	public static String getInput() {
		String input = null;
		
		try {
			do {
				input = JOptionPane.showInputDialog(null, message, title, type);
				
				input = input.trim();
				
				if (input.equals("")) {
					JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
				}
			}
			while (input.equals(""));
		}
		catch (Exception ex) {}
		
		return input;
	}
	
	public static void setInputDialog(Object newMessage, String newTitle, int newType) {
		setMessage(newMessage);
		setTitle(newTitle);
		setMessageType(newType);
	}
	
	public static void setMessage(Object newMessage) {
		message = newMessage;
	}
	
	public static void setTitle(String newTitle) {
		title = newTitle;
	}
	
	public static void setMessageType(int newType) {
		type = newType;
	}
	
	public static void setErrorDialog(Object newErrorMessage, String newErrorTitle) {
		setErrorMessage(newErrorMessage);
		setErrorTitle(newErrorTitle);
	}
	
	public static void setErrorMessage(Object newErrorMessage) {
		errorMessage = newErrorMessage;
	}
	
	public static void setErrorTitle(String newErrorTitle) {
		errorTitle = newErrorTitle;
	}
	
}
